package org.ee.protocol;

/**
 *
 * @Author zlj
 * @Date 2025/11/9 00:45
 */
import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelPipeline;
import io.netty.handler.codec.LineBasedFrameDecoder;
import io.netty.handler.codec.string.StringDecoder;
import io.netty.handler.codec.json.JsonObjectDecoder;
import io.netty.util.CharsetUtil;
import org.ee.core.ProtocolDefinition;

public class ProtocolB implements ProtocolDefinition {

    @Override
    public boolean matches(ByteBuf in) {
        byte first = in.getByte(in.readerIndex());
        return first == '{';  // JSON 开头
    }

    @Override
    public void setupPipeline(ChannelPipeline p) {
        p.addLast(new LineBasedFrameDecoder(8192));
        p.addLast(new StringDecoder(CharsetUtil.UTF_8));
        p.addLast(new JsonObjectDecoder());
        //p.addLast(new ProtocolBBusinessHandler());
    }

    @Override
    public String getName() {
        return "Protocol-B";
    }
}
